# coding:utf-8
import os

from bson import ObjectId
from flask import request, jsonify
from flask_restful import Resource
from app import api
from config import basepath

# 在线情感分析
# 基于情感词典
# in: 多个句子
# out: {code:0, data:[{'sentence':'', sentiment:0.9},
#                     {'sentence':'', sentiment:0.8},
#                      ],}
from service.article.articleOutlineService import ArticleOutlineService


class OnlineDictController(Resource):
    def post(self):
        text = request.form.get('text')
        print(text)
        result = ArticleOutlineService.dictSentiment(text)
        return result;

# 基于贝叶斯算法
class OnlineBeiyesController(Resource):
    def post(self):
        text = request.form.get('text')
        result = ArticleOutlineService.beiyesSentiment(text)
        return result


api.add_resource(OnlineDictController, '/api/online/dict')
api.add_resource(OnlineBeiyesController, '/api/online/bayes')